//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.facebook.ads;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.cpcphone.abtestcenter.sdk.HttpUtils;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class MediaView extends RelativeLayout {

    public MediaView(Context var1, AttributeSet var2) {
        super(var1, var2);
    }

    public MediaView(Context var1) {
        this(var1, (AttributeSet)null);
    }

    public void setNativeAd(NativeAd var1) {
        removeAllViews();
        final ImageView imageView = new ImageView(getContext());
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        HttpUtils.doGet(var1.getAdCoverImage().getUrl(), new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, final Response response) throws IOException {
                try {
                    byte[] bytes = response.body().bytes();
                    final Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                    post(new Runnable() {
                        @Override
                        public void run() {
                            imageView.setImageBitmap(bitmap);
                        }
                    });
                } catch (Throwable e) {
                    e.printStackTrace();
                }

            }
        });
        addView(imageView, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    }

    @Deprecated
    public boolean isAutoplay() {
        return false;
    }

    @Deprecated
    public void setAutoplayOnMobile(boolean var1) {
    }

    @Deprecated
    public void setAutoplay(boolean var1) {
    }

    public void destroy() {
        removeAllViews();
    }
}
